package com.fly.lambda.framework.aspect;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * Created by Fly on 2016/7/14.
 */
@Aspect
public class LogAspect {

    private final Log logger = LogFactory.getLog(this.getClass());

    @Pointcut("execution(* com.fly.lambda.service.*.*(..))")
    public void saveServiceCall(){
        logger.info("enter save service");
    }

    @AfterReturning(value="saveServiceCall()", argNames="rtv", returning="rtv")
    public void afterSaveServiceCall(JoinPoint joinPoint, Object rtv){
        String methodName = joinPoint.getSignature().getName();
        logger.info("方法名称：" +  methodName);
        if (joinPoint.getArgs() != null){
            String className;
            Object[] args = joinPoint.getArgs();
            String methodValue;
            for(Object obj : args){
                try {
                    logger.info(JSONObject.toJSONString(obj));
                }
                catch (Exception ex){
                    continue;
                }
            }
        }
    }

}
